package General;

import Building.allBuildings;
import java.util.ArrayList;

public class Board {
	Square[][] resourceArea;
	ArrayList<Tile> resourceList = new ArrayList<Tile>();
	allBuildings buildings = new allBuildings();
	ArrayList<Unit> holdingArea;
	private static final int BOARD_SIZE=4;
	public Board(int culture){
		resourceArea = Culture.getSquare(culture);
		buildings = new allBuildings();
	}
	public  void recruit(Unit unit){
		holdingArea.add(unit);
	}
/*	public boolean searchBuilding(Building b){
		if (buildingList.isEmpty()) return false;
		else return buildingList.contains(b);
	}*/
	public Unit[] getUnits(){
		return (Unit[])holdingArea.toArray();
	}
	/**
	 * method for All resource types
	 */
	public Resource gather(){
		Resource totalYield = new Resource();
		for(int x = 0; x< BOARD_SIZE; x++){
			for(int y = 0; y< BOARD_SIZE; y++){
					totalYield = totalYield.addResource(resourceArea[x][y].getYield());
			}
		}
		return totalYield;
	}
	/**
	 * method for terrain type gathering
	 * @param type terrain type
	 * @return
	 */
	public Resource gather(Terrain type){	//0 terrain type, 1 resource type, 2 all
		Resource totalYield = new Resource();
		for(int x = 0; x< BOARD_SIZE; x++){
			for(int y = 0; y< BOARD_SIZE; y++){
				if(resourceArea[x][y].getTerrain()==type){
					totalYield = totalYield.addResource(resourceArea[x][y].getYield());
				}
			}
		}
		return totalYield;
	}
	public Resource gather(Resources type){
		Resource totalYield = new Resource();
		for(int x = 0; x< BOARD_SIZE; x++){
			for(int y = 0; y< BOARD_SIZE; y++){
				if(resourceArea[x][y].getTileType()==type){
					totalYield = totalYield.addResource(resourceArea[x][y].getYield());
				}
			}
		}
		return totalYield;
	}
	public Terrain getTerrain(int x, int y){
		return resourceArea[x][y].getTerrain();
	}
	public Resources getTileType(int x, int y){
		return resourceArea[x][y].getTileType();
	}
	public boolean attachTile(int x, int y, Tile tile){
		return resourceArea[x][y].attachTile(tile);
	}
}
